Uec3.PresentServiceWindow = Ext.extend(Ext.app.Module,{
	id: 'presentService',
   init : function(initParams){
   
   },
 
   getComponent:function(params){
      	var companyId = params.companyId;    
   		var companyName=params.companyName;
   		var giftCondition_Store = getDictionaryStore(Uec3.App.Constants.homeUrl,{group:'package_giftCondition'});
   	    var giftCondition_combox = getDictionaryComboBox(giftCondition_Store,'local','giftCondition','赠送条件','giftCondition','','100%');
   		   		
   		var add_form =new Ext.FormPanel({
   		    border:false,
   		    frame:true,
   		    labelWidth:80,
   		    items:[
   		       {
   		          layout:'form',
   		          items:[{xtype:'hidden',name:'companyId',value:companyId},
   		          	     {xtype:'textfield',fieldLabel:'公司名称',name:'companyName',anchor:'100%',value:companyName,disabled:true}]
   		       },{
   		          xtype:'fieldset',
   		          title : '包含服务',
   		          itemId:'service_checkGroup',
   		          autoHeight:true    
   		       }
   		    ],
   		    buttons: [{
                  text: '确定',
                  handler: addPackage
   		       },{
   		          text:'清空',
   		          handler: function(){
   		          	 add_form.buttons[0].enable();
   		             add_form.getForm().reset();
   		          }
   		       },{
                  text: '取消',
                  handler: function(){
                     add_form.ownerCt.close();
                  }
            }],
            buttonAlign:'center'
   		    
   		});
   		
   		
   	    function init(){
   	       giftCondition_Store.load();  	      	       
   	    }   	    
   	    init();
   	    
   	   
   		function getServiceCheckGroup(){
   			
   			  var service_checkGroup=[];     
   			
				Ext.Ajax.request({
					waitMsg:'请稍后.....',
					waitTitle:'提示',
					url:Uec3.App.Constants.homeUrl+"/companyPackage/listSendService.do?companyId="+companyId, 
			        success:function(response,options){
			        	var result = Ext.decode(response.responseText);
			            var all=result.root;
			            var has=result.present;
			            var flag=false;
			            for(var i=0;i<all.length;i++){
			            	flag=false;
			              for(var j=0;j<has.length;j++){
			              	
			              	if(has[j].serviceId==all[i].id){
			              		flag=true;
			              		break;
			              	}
			              	
			              }
			              if(flag){
			              	var item = {boxLabel:all[i].name,name:'serviceIds',inputValue:all[i].id,checked: true};
			              }else{
			              	var item = {boxLabel:all[i].name,name:'serviceIds',inputValue:all[i].id}; 
			              }
			              
   	                      service_checkGroup.push(item);
			            }

   	                 var checkGroup = new Ext.form.CheckboxGroup({
   	                     fieldLabel: '选择包含服务',
   	                     allowBlank : true,
   	                     width : 360,
					     columns: 3,
                         items:service_checkGroup
   	                 });
   	                 add_form.getComponent("service_checkGroup").add(checkGroup); 
   	                 add_form.doLayout();
   	             
			        },
			      failure:function(form,action){
			          Ext.Msg.alert('提示','加载数据失败  ');
			      }
			});
   		}
   	                
   	    
   	    getServiceCheckGroup();
   	    
   	    function addPackage(){
            if(add_form.getForm().isValid()){
               Ext.MessageBox.confirm("提示","确定此项操作?",function(btnId){
                    if(btnId == 'yes'){
                       var myMask = new Ext.LoadMask(add_form.ownerCt.el,{msg : "正在保存,请稍后....." });
                        myMask.show(); 
                        var queryParam = Ext.encode(add_form.getForm().getValues());
                        Ext.Ajax.request({		            
				      		url:Uec3.App.Constants.homeUrl+"/companyPackage/presentSave.do",
				      		method :"post",					   
				      		params:{jsonData:queryParam},
				      		timeout:180000,
                      		success:function(response,options){
                      	 		var resp = Ext.decode(response.responseText);
				         		Ext.Msg.alert("提示",resp.msg);
				         		myMask.hide();
				         		add_form.buttons[0].disable();
                      		},
                      		failure:function(response,options){
                         		Ext.Msg.alert("提示","发生异常,保存失败!");
                         		myMask.hide();
                      		}
		      			}); 
                    }               	
               });    	
            }
        } 
   	    
   	    return add_form;
   },
   
   /**
	* Create this modules window here.
	*/
   createWindow : function(params){
    	var desktop = this.app.getDesktop();
        var win = desktop.getWindow('presentServiceWindow');
        if (!win) {
			win = desktop.createWindow({
				        id : "presentServiceWindow",
						title : '开通或停止服务',
						width : 500,
						autoHeight : true,
						iconCls : 'acc-icon',
						maximizable : true,
						resizable:false,
						maximized:false,
						constrainHeader : true,
						taskbuttonTooltip : "开通或停止服务",
						items : [this.getComponent(params)]
					});
		} 
    	win.show();         
   }
});